<template>
  <!-- 底部 -->
  <div class="my-footer">
    <!-- 全选 -->
    <div class="custom-control custom-checkbox">
      <input type="checkbox" class="custom-control-input" id="footerCheck" v-model="isAll">
      <label class="custom-control-label" for="footerCheck">全选</label>
    </div>
    <!-- 合计 -->
    <div>
      <span>合计:</span>
      <span class="price">¥ {{total}}</span>
    </div>
    <!-- 按钮 -->
    <button type="button" class="footer-btn btn btn-primary" @click="jiesuan">结算 {{sum}}</button>
  </div>
</template>

<script>
export default {
     props:{
     
      list:{
        type:Array
      }
     },
     data(){
      return {
         total:0
      }
     },
    computed:{
      isAll:{
        get(){
        return  this.list.every(item=>item.goods_state)
        },
        set(val){
           this.list.filter(item=>item.goods_state = val)
        }
      },
      // total:{
      //   get(){
      //      const arr=  this.list.filter(item=>item.goods_state)
      //      console.log(arr);
      //     return   arr.reduce(function(sum,item){
      //           sum= sum + item.goods_price * item.goods_count
      //       },0)
           
      //   }
     
      // },
      sum:{
        get(){
           const arr=  this.list.filter(item=>item.goods_state)
            return arr.length
        }
      },
       
    },
    methods:{
      jiesuan(){
         const arr = this.list.filter(item=>item.goods_state)
          console.log(arr);
       const res =    arr.reduce(function(sum,item){
            return  sum+= item.goods_price *item.goods_count
           },0)
           console.log(res);
           this.total = res
      }
    }
    
}
</script>

<style lang="less" scoped>
.my-footer {
  position: fixed;
  z-index: 2;
  bottom: 0;
  width: 100%;
  height: 50px;
  border-top: 1px solid #ccc;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 10px;
  background: #fff;

  .price {
    color: red;
    font-weight: bold;
    font-size: 15px;
  }
  .footer-btn {
    min-width: 80px;
    height: 30px;
    line-height: 30px;
    border-radius: 25px;
    padding: 0;
  }
}
</style>